import React from "react";

export default class App extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            counter: 0
        }
    }

    render() {
        return (
            <div>
                <h2>当前数字：{this.state.counter}</h2>
                <button onClick={e => this.increment()}>+1</button>
            </div>
        )
    }

    componentDidUpdate() {
        console.log(this.state.counter)
    }

    increment() {
        // this.state.counter += 1
        // console.log(this.state.counter)
        this.setState({
            counter: this.state.counter += 1
        },() => {
            //console.log(this.state.counter)
        })
    }
}